@palco-2d/core / Scene
Class: Scene
Defined in: src/SceneHandler/Scene.ts:14
The Scene class serves as the core component of Palco 2D, providing the foundation for creating and managing 2D scenes. It integrates a renderer and mouse handler to enable visual rendering and interactive functionality, along with additional abstractions
Constructors
new Scene()
new Scene():
Scene
Defined in: src/SceneHandler/Scene.ts:51
Returns
Properties
canvas
canvas:
HTMLCanvasElement
Defined in: src/SceneHandler/Scene.ts:18
The HTML canvas element the scene renders to.
ctx
ctx:
CanvasRenderingContext2D
Defined in: src/SceneHandler/Scene.ts:29
The 2D rendering context of the canvas.
eventHandler
eventHandler:
SceneEventHandlers
Defined in: src/SceneHandler/Scene.ts:49
The scene handler provides ways to subscribe to specific scene events such as adding or removing entities for example.
mouseHandler
mouseHandler:
MouseHandler
Defined in: src/SceneHandler/Scene.ts:39
Handles mouse interactions within the scene, detecting when the cursor hovers over an entity and dispatching relevant mouse events to subscribed entities.
render
render:
RenderHandler
Defined in: src/SceneHandler/Scene.ts:34
The rendering handler for the scene. Responsible for rendering entities and plugins to the canvas.
upperCanvas
upperCanvas:
HTMLCanvasElement
Defined in: src/SceneHandler/Scene.ts:24
The HTML canvas element the scene used by scene plugins. to render on top of the main canvas, without interfering with the main canvas.
Methods
addEntities()
addEntities(
entities):void
Defined in: src/SceneHandler/Scene.ts:165
Adds entities to the scene. under the hood, adds each entity in the array to the render handler and consequentially to the mouseHandler to enable mouse interactions.
Parameters
entities
Returns
void
addEntity()
addEntity(
entity):void
Defined in: src/SceneHandler/Scene.ts:155
Adds an entity to the scene. under the hood, adds the entity to the render handler and consequentially to the mouseHandler to enable mouse interactions.
Parameters
entity
Returns
void
addPlugin()
addPlugin(
Plugin,key):void
Defined in: src/SceneHandler/Scene.ts:106
add the plugin to the scene, to run the custom logic of the plugin, the plugin must be started.
Parameters
Plugin
typeof ScenePlugin
The plugin to add to the scene.
key
string
Returns
void
getPlugin()
getPlugin(
key):ScenePlugin
Defined in: src/SceneHandler/Scene.ts:136
Returns the plugin with the given key.
Parameters
key
string
The key of the plugin to retrieve.
Returns
pause()
pause():
void
Defined in: src/SceneHandler/Scene.ts:96
Pauses the render and mouse handler, without terminating the scene instance or entities. Stops rendering and calculating any interatction but keep the scene and entities alive, so on start, a re-creation of the scene is not needed.
Returns
void
removeEntity()
removeEntity(
entity):void
Defined in: src/SceneHandler/Scene.ts:175
Removes an entity from the scene. under the hood, removes the entity from the render handler and consequentially from the mouseHandler
Parameters
entity
Returns
void
removePlugin()
removePlugin(
key):void
Defined in: src/SceneHandler/Scene.ts:121
Removes the plugin from the scene.
Parameters
key
string
The key of the plugin to remove. on removing, the custom logic of the plugin will be stopped.
Returns
void
start()
start():
Promise<void>
Defined in: src/SceneHandler/Scene.ts:70
Starts the custom scene logic, here you the code you create will be triggered, It's the perfect place to create all the entities and plugins you need and add them to the scene.
Returns
Promise<void>
startAllPlugins()
startAllPlugins():
void
Defined in: src/SceneHandler/Scene.ts:144
Starts the plugins added to the scene. All Scene plugins start method will be called.
Returns
void
stop()
stop():
void
Defined in: src/SceneHandler/Scene.ts:79
Stops render and mouse handler from running.
It also stops all the plugins added to the scene.
When creating you custom scene, for best practices, you should call this method
super.stop() before adding your custom logic, to ensure that the scene is properly stopped.
it's the perfect place to remove any window listeners or clear any intervals that you might have created.
Returns
void